{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
    "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/kaggle/input/ieee-fraud-detection/sample_submission.csv\n",
      "/kaggle/input/ieee-fraud-detection/test_identity.csv\n",
      "/kaggle/input/ieee-fraud-detection/train_transaction.csv\n",
      "/kaggle/input/ieee-fraud-detection/test_transaction.csv\n",
      "/kaggle/input/ieee-fraud-detection/train_identity.csv\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/__output__.json\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/X_train2.pkl\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/custom.css\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/__results__.html\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/__notebook__.ipynb\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/y_train2.pkl\n",
      "/kaggle/input/ieee-cis-12nd-solution-part-1/X_test2.pkl\n"
     ]
    }
   ],
   "source": [
    "# This Python 3 environment comes with many helpful analytics libraries installed\n",
    "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
    "# For example, here's several helpful packages to load in \n",
    "\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "\n",
    "# Input data files are available in the \"../input/\" directory.\n",
    "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
    "\n",
    "import os\n",
    "for dirname, _, filenames in os.walk('/kaggle/input'):\n",
    "    for filename in filenames:\n",
    "        print(os.path.join(dirname, filename))\n",
    "\n",
    "# Any results you write to the current directory are saved as output."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "_cell_guid": "79c7e3d0-c299-4dcb-8224-4455121ee9b0",
    "_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt \n",
    "from sklearn import preprocessing\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "import catboost as cb\n",
    "import lightgbm as lgb\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.model_selection import GridSearchCV, StratifiedKFold,TimeSeriesSplit,KFold,GroupKFold\n",
    "from sklearn.metrics import roc_auc_score\n",
    "import sqlite3\n",
    "import xgboost as xgb\n",
    "import datetime\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from scipy.stats import pearsonr\n",
    "import gc\n",
    "from sklearn.model_selection import TimeSeriesSplit\n",
    "import hashlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "__print__ = print\n",
    "def print(string):\n",
    "    __print__(string)\n",
    "    os.system(f'echo \\\"{string}\\\"')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train = pd.read_pickle('../input/ieee-cis-12nd-solution-part-1/X_train2.pkl')\n",
    "y_train = pd.read_pickle('../input/ieee-cis-12nd-solution-part-1/y_train2.pkl')\n",
    "y_train = y_train.isFraud"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Memory Reducer\n",
    "# :df pandas dataframe to reduce size             # type: pd.DataFrame()\n",
    "# :verbose                                        # type: bool\n",
    "def reduce_mem_usage(df, verbose=True):\n",
    "    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']\n",
    "    start_mem = df.memory_usage().sum() / 1024**2    \n",
    "    for col in df.columns:\n",
    "        col_type = df[col].dtypes\n",
    "        if col_type in numerics:\n",
    "            c_min = df[col].min()\n",
    "            c_max = df[col].max()\n",
    "            if str(col_type)[:3] == 'int':\n",
    "                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n",
    "                    df[col] = df[col].astype(np.int8)\n",
    "                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n",
    "                    df[col] = df[col].astype(np.int16)\n",
    "                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n",
    "                    df[col] = df[col].astype(np.int32)\n",
    "                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n",
    "                    df[col] = df[col].astype(np.int64)  \n",
    "            else:\n",
    "                if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n",
    "                    df[col] = df[col].astype(np.float16)\n",
    "                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n",
    "                    df[col] = df[col].astype(np.float32)\n",
    "                else:\n",
    "                    df[col] = df[col].astype(np.float64)    \n",
    "    end_mem = df.memory_usage().sum() / 1024**2\n",
    "    if verbose: print('Mem. usage decreased to {:5.2f} Mb ({:.1f}% reduction)'.format(end_mem, 100 * (start_mem - end_mem) / start_mem))\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mem. usage decreased to 472.51 Mb (70.8% reduction)\n",
      "CPU times: user 38.9 s, sys: 1min 58s, total: 2min 37s\n",
      "Wall time: 2min 37s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "X_train = reduce_mem_usage(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat = ['uid1', 'id_13', 'id_14', 'id_15', 'id_16', 'id_17', 'id_18', 'id_19', 'id_20', 'id_21', 'id_22', 'id_23', 'id_24', 'id_25', 'id_26', 'id_27', 'id_28', 'id_29',\n",
    "            'id_30', 'id_31', 'id_32', 'id_33', 'id_34', 'id_35', 'id_36', 'id_37', 'id_38', 'DeviceType', 'ProductCD', 'card4', 'card6', 'M4','P_emaildomain',\n",
    "            'R_emaildomain', 'card1', 'card2', 'card3',  'card5', 'addr1', 'addr2', 'M1', 'M2', 'M3', 'M5', 'M6', 'M7', 'M8', 'M9','hour','dow','device_name', 'OS_id_30',  'browser_id_31','ProductID',\n",
    "'DeviceInfo__P_emaildomain', \n",
    "        'card1__card5', \n",
    "        'card2__id_20',\n",
    "        'card5__P_emaildomain', \n",
    "        'addr1__card1',\n",
    "        'addr1__addr2',\n",
    "        'card1__card2',\n",
    "        'card2__addr1',\n",
    "        'card1__P_emaildomain',\n",
    "        'card2__P_emaildomain',\n",
    "        'addr1__P_emaildomain',\n",
    "        'DeviceInfo__id_31',\n",
    "        'DeviceInfo__id_20',\n",
    "        'DeviceType__id_31',\n",
    "        'DeviceType__id_20',\n",
    "        'DeviceType__P_emaildomain',\n",
    "        'card1__M4',\n",
    "        'card2__M4',\n",
    "        'addr1__M4',\n",
    "        'P_emaildomain__M4',\n",
    "       'uid1__ProductID',\n",
    "       'uid1__DeviceInfo']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "cat = list(set(cat) & set(X_train.columns))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "check1\n",
      "0:\tlearn: 0.9345614\ttest: 0.8018864\tbest: 0.8018864 (0)\ttotal: 384ms\tremaining: 10h 39m 11s\n",
      "100:\tlearn: 0.9810826\ttest: 0.9298821\tbest: 0.9298821 (100)\ttotal: 33.8s\tremaining: 9h 17m 20s\n",
      "200:\tlearn: 0.9841646\ttest: 0.9374748\tbest: 0.9374748 (200)\ttotal: 1m 8s\tremaining: 9h 29m 38s\n",
      "300:\tlearn: 0.9859747\ttest: 0.9414260\tbest: 0.9414260 (300)\ttotal: 1m 44s\tremaining: 9h 36m 52s\n",
      "400:\tlearn: 0.9876147\ttest: 0.9434797\tbest: 0.9434797 (400)\ttotal: 2m 20s\tremaining: 9h 40m 32s\n",
      "500:\tlearn: 0.9890458\ttest: 0.9455784\tbest: 0.9456552 (467)\ttotal: 2m 55s\tremaining: 9h 42m 30s\n",
      "600:\tlearn: 0.9903550\ttest: 0.9472303\tbest: 0.9472303 (600)\ttotal: 3m 31s\tremaining: 9h 43m 9s\n",
      "700:\tlearn: 0.9913670\ttest: 0.9477966\tbest: 0.9478087 (699)\ttotal: 4m 6s\tremaining: 9h 42m 46s\n",
      "800:\tlearn: 0.9923909\ttest: 0.9481949\tbest: 0.9482264 (798)\ttotal: 4m 42s\tremaining: 9h 43m 19s\n",
      "900:\tlearn: 0.9933137\ttest: 0.9491072\tbest: 0.9491757 (882)\ttotal: 5m 18s\tremaining: 9h 43m 9s\n",
      "1000:\tlearn: 0.9942666\ttest: 0.9499893\tbest: 0.9499896 (997)\ttotal: 5m 54s\tremaining: 9h 43m 55s\n",
      "1100:\tlearn: 0.9950768\ttest: 0.9499955\tbest: 0.9500689 (1079)\ttotal: 6m 30s\tremaining: 9h 44m 48s\n",
      "1200:\tlearn: 0.9956483\ttest: 0.9497154\tbest: 0.9500689 (1079)\ttotal: 7m 6s\tremaining: 9h 45m 5s\n",
      "1300:\tlearn: 0.9963208\ttest: 0.9494797\tbest: 0.9500689 (1079)\ttotal: 7m 42s\tremaining: 9h 44m 46s\n",
      "1400:\tlearn: 0.9968560\ttest: 0.9484230\tbest: 0.9500689 (1079)\ttotal: 8m 18s\tremaining: 9h 44m 25s\n",
      "bestTest = 0.950068891\n",
      "bestIteration = 1079\n",
      "Shrink model to first 1080 iterations.\n",
      "check2\n",
      "0.9500689917175684\n",
      "check3\n",
      "check4\n",
      "check1\n",
      "0:\tlearn: 0.9226105\ttest: 0.8778858\tbest: 0.8778858 (0)\ttotal: 353ms\tremaining: 9h 47m 56s\n",
      "100:\tlearn: 0.9784018\ttest: 0.9550341\tbest: 0.9550341 (100)\ttotal: 33.3s\tremaining: 9h 9m 12s\n",
      "200:\tlearn: 0.9813720\ttest: 0.9587491\tbest: 0.9587514 (199)\ttotal: 1m 7s\tremaining: 9h 20m 1s\n",
      "300:\tlearn: 0.9835145\ttest: 0.9601564\tbest: 0.9602024 (296)\ttotal: 1m 43s\tremaining: 9h 31m 6s\n",
      "400:\tlearn: 0.9852737\ttest: 0.9608390\tbest: 0.9609674 (387)\ttotal: 2m 18s\tremaining: 9h 33m 28s\n",
      "500:\tlearn: 0.9868741\ttest: 0.9615542\tbest: 0.9615542 (500)\ttotal: 2m 54s\tremaining: 9h 36m 20s\n",
      "600:\tlearn: 0.9883923\ttest: 0.9618014\tbest: 0.9618579 (588)\ttotal: 3m 29s\tremaining: 9h 38m 6s\n",
      "700:\tlearn: 0.9896991\ttest: 0.9624033\tbest: 0.9624160 (696)\ttotal: 4m 5s\tremaining: 9h 38m 32s\n",
      "800:\tlearn: 0.9910368\ttest: 0.9625140\tbest: 0.9626223 (775)\ttotal: 4m 40s\tremaining: 9h 39m 21s\n",
      "900:\tlearn: 0.9921305\ttest: 0.9625038\tbest: 0.9627004 (884)\ttotal: 5m 16s\tremaining: 9h 39m 25s\n",
      "1000:\tlearn: 0.9931551\ttest: 0.9624847\tbest: 0.9627004 (884)\ttotal: 5m 52s\tremaining: 9h 40m 37s\n",
      "1100:\tlearn: 0.9940293\ttest: 0.9616513\tbest: 0.9627004 (884)\ttotal: 6m 27s\tremaining: 9h 40m 14s\n",
      "1200:\tlearn: 0.9947537\ttest: 0.9613057\tbest: 0.9627004 (884)\ttotal: 7m 3s\tremaining: 9h 41m 3s\n",
      "bestTest = 0.962700367\n",
      "bestIteration = 884\n",
      "Shrink model to first 885 iterations.\n",
      "check2\n",
      "0.962700415947033\n",
      "check3\n",
      "check4\n",
      "check1\n",
      "0:\tlearn: 0.9228046\ttest: 0.8009977\tbest: 0.8009977 (0)\ttotal: 309ms\tremaining: 8h 35m 31s\n",
      "100:\tlearn: 0.9791834\ttest: 0.9528808\tbest: 0.9528808 (100)\ttotal: 33.2s\tremaining: 9h 7m 49s\n",
      "200:\tlearn: 0.9824235\ttest: 0.9565046\tbest: 0.9565987 (199)\ttotal: 1m 7s\tremaining: 9h 15m 31s\n",
      "300:\tlearn: 0.9845701\ttest: 0.9579296\tbest: 0.9579296 (300)\ttotal: 1m 42s\tremaining: 9h 26m 20s\n",
      "400:\tlearn: 0.9863313\ttest: 0.9590738\tbest: 0.9591072 (392)\ttotal: 2m 18s\tremaining: 9h 32m 30s\n",
      "500:\tlearn: 0.9879196\ttest: 0.9598535\tbest: 0.9600084 (483)\ttotal: 2m 53s\tremaining: 9h 35m 16s\n",
      "600:\tlearn: 0.9892532\ttest: 0.9603165\tbest: 0.9603267 (597)\ttotal: 3m 29s\tremaining: 9h 37m 48s\n",
      "700:\tlearn: 0.9904057\ttest: 0.9608707\tbest: 0.9608707 (700)\ttotal: 4m 5s\tremaining: 9h 39m 11s\n",
      "800:\tlearn: 0.9914156\ttest: 0.9608561\tbest: 0.9609726 (762)\ttotal: 4m 40s\tremaining: 9h 38m 46s\n",
      "900:\tlearn: 0.9924269\ttest: 0.9614480\tbest: 0.9614480 (900)\ttotal: 5m 15s\tremaining: 9h 38m 2s\n",
      "1000:\tlearn: 0.9933619\ttest: 0.9617407\tbest: 0.9617553 (999)\ttotal: 5m 51s\tremaining: 9h 39m 16s\n",
      "1100:\tlearn: 0.9942189\ttest: 0.9617419\tbest: 0.9618328 (1032)\ttotal: 6m 27s\tremaining: 9h 39m 38s\n",
      "1200:\tlearn: 0.9951040\ttest: 0.9617172\tbest: 0.9618706 (1118)\ttotal: 7m 3s\tremaining: 9h 40m 34s\n",
      "1300:\tlearn: 0.9958546\ttest: 0.9617690\tbest: 0.9618706 (1118)\ttotal: 7m 39s\tremaining: 9h 40m 48s\n",
      "1400:\tlearn: 0.9964572\ttest: 0.9616573\tbest: 0.9618706 (1118)\ttotal: 8m 15s\tremaining: 9h 40m 46s\n",
      "1500:\tlearn: 0.9969546\ttest: 0.9615543\tbest: 0.9618706 (1118)\ttotal: 8m 51s\tremaining: 9h 41m 20s\n",
      "bestTest = 0.9618706107\n",
      "bestIteration = 1118\n",
      "Shrink model to first 1119 iterations.\n",
      "check2\n",
      "0.9618705553689192\n",
      "check3\n",
      "check4\n",
      "check1\n",
      "0:\tlearn: 0.9160827\ttest: 0.8765992\tbest: 0.8765992 (0)\ttotal: 315ms\tremaining: 8h 44m 57s\n",
      "100:\tlearn: 0.9784115\ttest: 0.9638722\tbest: 0.9638722 (100)\ttotal: 33.8s\tremaining: 9h 17m 21s\n",
      "200:\tlearn: 0.9817520\ttest: 0.9665000\tbest: 0.9665000 (200)\ttotal: 1m 8s\tremaining: 9h 29m 8s\n",
      "300:\tlearn: 0.9838901\ttest: 0.9678137\tbest: 0.9678137 (300)\ttotal: 1m 44s\tremaining: 9h 34m 24s\n",
      "400:\tlearn: 0.9860299\ttest: 0.9690283\tbest: 0.9690541 (398)\ttotal: 2m 20s\tremaining: 9h 40m 11s\n",
      "500:\tlearn: 0.9877259\ttest: 0.9698229\tbest: 0.9698229 (500)\ttotal: 2m 55s\tremaining: 9h 41m 58s\n",
      "600:\tlearn: 0.9892005\ttest: 0.9702752\tbest: 0.9702763 (597)\ttotal: 3m 31s\tremaining: 9h 42m 35s\n",
      "700:\tlearn: 0.9903756\ttest: 0.9705187\tbest: 0.9706108 (680)\ttotal: 4m 6s\tremaining: 9h 42m 42s\n",
      "800:\tlearn: 0.9914119\ttest: 0.9707306\tbest: 0.9708724 (718)\ttotal: 4m 42s\tremaining: 9h 43m 11s\n",
      "900:\tlearn: 0.9924275\ttest: 0.9706334\tbest: 0.9708893 (821)\ttotal: 5m 18s\tremaining: 9h 43m 36s\n",
      "1000:\tlearn: 0.9934075\ttest: 0.9706219\tbest: 0.9708893 (821)\ttotal: 5m 54s\tremaining: 9h 44m 30s\n",
      "1100:\tlearn: 0.9941797\ttest: 0.9705746\tbest: 0.9708893 (821)\ttotal: 6m 30s\tremaining: 9h 44m 37s\n",
      "1200:\tlearn: 0.9949995\ttest: 0.9704758\tbest: 0.9708893 (821)\ttotal: 7m 7s\tremaining: 9h 45m 38s\n",
      "bestTest = 0.9708892703\n",
      "bestIteration = 821\n",
      "Shrink model to first 822 iterations.\n",
      "check2\n",
      "0.9708892378803563\n",
      "check3\n",
      "check4\n",
      "check1\n",
      "0:\tlearn: 0.9202620\ttest: 0.8507767\tbest: 0.8507767 (0)\ttotal: 317ms\tremaining: 8h 49m 9s\n",
      "100:\tlearn: 0.9795624\ttest: 0.9403198\tbest: 0.9403478 (98)\ttotal: 33.1s\tremaining: 9h 5m 14s\n",
      "200:\tlearn: 0.9826308\ttest: 0.9432717\tbest: 0.9433540 (195)\ttotal: 1m 8s\tremaining: 9h 23m 2s\n",
      "300:\tlearn: 0.9848859\ttest: 0.9449448\tbest: 0.9449655 (297)\ttotal: 1m 44s\tremaining: 9h 35m 33s\n",
      "400:\tlearn: 0.9863163\ttest: 0.9455399\tbest: 0.9455515 (381)\ttotal: 2m 19s\tremaining: 9h 39m 12s\n",
      "500:\tlearn: 0.9879995\ttest: 0.9459795\tbest: 0.9461169 (466)\ttotal: 2m 55s\tremaining: 9h 41m 9s\n",
      "600:\tlearn: 0.9894867\ttest: 0.9461202\tbest: 0.9461206 (596)\ttotal: 3m 31s\tremaining: 9h 43m 2s\n",
      "700:\tlearn: 0.9909008\ttest: 0.9455360\tbest: 0.9461504 (626)\ttotal: 4m 7s\tremaining: 9h 45m 15s\n",
      "800:\tlearn: 0.9920639\ttest: 0.9456280\tbest: 0.9461504 (626)\ttotal: 4m 43s\tremaining: 9h 45m 51s\n",
      "900:\tlearn: 0.9930721\ttest: 0.9459288\tbest: 0.9461504 (626)\ttotal: 5m 19s\tremaining: 9h 45m 49s\n",
      "1000:\tlearn: 0.9939316\ttest: 0.9459146\tbest: 0.9462678 (931)\ttotal: 5m 55s\tremaining: 9h 46m 1s\n",
      "1100:\tlearn: 0.9947731\ttest: 0.9461071\tbest: 0.9462678 (931)\ttotal: 6m 31s\tremaining: 9h 46m 19s\n",
      "1200:\tlearn: 0.9954031\ttest: 0.9460357\tbest: 0.9462678 (931)\ttotal: 7m 7s\tremaining: 9h 45m 38s\n",
      "1300:\tlearn: 0.9960423\ttest: 0.9463867\tbest: 0.9463867 (1300)\ttotal: 7m 42s\tremaining: 9h 44m 53s\n",
      "1400:\tlearn: 0.9966705\ttest: 0.9467447\tbest: 0.9468520 (1349)\ttotal: 8m 19s\tremaining: 9h 45m 21s\n",
      "1500:\tlearn: 0.9971908\ttest: 0.9461764\tbest: 0.9468520 (1349)\ttotal: 8m 56s\tremaining: 9h 46m 23s\n",
      "1600:\tlearn: 0.9975856\ttest: 0.9466178\tbest: 0.9468520 (1349)\ttotal: 9m 31s\tremaining: 9h 45m 50s\n",
      "1700:\tlearn: 0.9979845\ttest: 0.9463131\tbest: 0.9468520 (1349)\ttotal: 10m 8s\tremaining: 9h 45m 36s\n",
      "bestTest = 0.9468519688\n",
      "bestIteration = 1349\n",
      "Shrink model to first 1350 iterations.\n",
      "check2\n",
      "0.9468518781395882\n",
      "check3\n",
      "check4\n",
      "End:0.958476215810693\n"
     ]
    }
   ],
   "source": [
    "kf=KFold(n_splits = 5)\n",
    "resu1 = 0\n",
    "impor1 = 0\n",
    "y_pred = 0\n",
    "stack_train = np.zeros([X_train.shape[0],])\n",
    "\n",
    "\n",
    "\n",
    "for train_index, test_index in kf.split(X_train, y_train):\n",
    "    \n",
    "    X_train = pd.read_pickle('../input/ieee-cis-12nd-solution-part-1/X_train2.pkl')\n",
    "    X_train = reduce_mem_usage(X_train, verbose=False)\n",
    "    X_train2= X_train.iloc[train_index,:]\n",
    "    y_train2= y_train.iloc[train_index]\n",
    "    X_test2= X_train.iloc[test_index,:]\n",
    "    y_test2= y_train.iloc[test_index]\n",
    "    \n",
    "    del X_train\n",
    "    print('check1')\n",
    "    clf = cb.CatBoostClassifier(n_estimators=100000, random_state=0, learning_rate= 0.1,depth=10,cat_features = cat,task_type = 'GPU', #learning_rate= 0.05\n",
    "                               early_stopping_rounds = 400,eval_metric='AUC',border_count = 254,l2_leaf_reg=2)\n",
    "    clf.fit(X_train2,y_train2,eval_set = (X_test2,y_test2),verbose=100)\n",
    "    del X_train2,y_train2\n",
    "    \n",
    "    print('check2')\n",
    "    temp_predict = clf.predict_proba(X_test2)[:,1]\n",
    "    roc = roc_auc_score(y_test2, temp_predict)\n",
    "    stack_train[test_index] = temp_predict\n",
    "    print(roc)\n",
    "    del X_test2,y_test2\n",
    "    \n",
    "    print('check3')\n",
    "    X_test = pd.read_pickle('../input/ieee-cis-12nd-solution-part-1/X_test2.pkl')\n",
    "    X_test = reduce_mem_usage(X_test, verbose=False)\n",
    "    y_pred += clf.predict_proba(X_test)[:,1]/5\n",
    "    del X_test\n",
    "    \n",
    "    print('check4')\n",
    "    resu1 += roc/5\n",
    "    impor1 += clf.feature_importances_/5\n",
    "    gc.collect()\n",
    "print(f'End:{resu1}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "resu = pd.read_csv('../input/ieee-fraud-detection/sample_submission.csv')\n",
    "resu['isFraud'] = y_pred\n",
    "resu.to_csv('cat.csv',index=False)\n",
    "a= pd.DataFrame()\n",
    "a['train'] = stack_train\n",
    "a.to_csv('cat_train.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
